<?php
class ToolAction extends Action {
	public function doUpload() {
		$this->success('ok',$this->upload());
	}

	public function doDeload($par) {
		if (!isset ($par['path'])) {
			$this->error('无文件路径', 1);
			return false;
		}
		$uppath = $this->getSetting('upload_path');
		if (strpos($par['path'], $uppath)) {
			$this->error('文件路径不合法', 1);
			return false;
		}
		if (!file_exists($par['path'])) {
			$this->error('文件不存在', 1);
			return false;
		}
		if (!unlink($par['path'])) {
			$this->error('文件删除失败', 1);
			return false;
		}
		$this->rs = true;
		$this->success('删除成功', 1);
		return true;
	}

	public function upload() {
		$filestatus = array ();
		import("ORG.Net.UploadFile");
		$upload = new UploadFile();
		$upload->maxSize = -1;
		$upload->allowExts = array (
			'jpg',
			'gif',
			'png',
			'zip',
			'rar',
			'7z',
			'doc',
			'docx',
			'xls',
			'xlsx',
			'ppt',
			'pptx',
			'pps',
			'pdf',
			'swf'
		);
		$uppath = $this->getSetting('upload_path');
		if(strrchr($uppath,'/') != '/') $uppath = $uppath.'/';
		if (!file_exists($uppath))
			@ mkdir($uppath, 0777);
		$upload->savePath = $uppath;
		$upload->autoSub = true;
		$upload->subType = 'date';
		//$upload->hashLevel = 2;
		$upload->dateFormat = 'Y_m_d';
		$upload->saveRule = uniqid;
		if (!$upload->upload()) {
			//捕获上传异常
			$this->error($upload->getErrorMsg(), 0);
			return false;
		} else {
			//取得成功上传的文件信息
			$uploadList = $upload->getUploadFileInfo();
			//key ：附件上传的表单名称 
			//savepath ：上传文件的保存路径 
			//name ：上传文件的原始名称 
			//savename ：上传文件的保存名称 
			//size ：上传文件的大小 
			//type ：上传文件的 MIME 类型 
			//extension ：上传文件的后缀类型 
			//hash ：上传文件的哈希验证字符串 
			//file_store_path 	file_real_name 
			$filedata = array ();
			foreach ($uploadList as $afile) {
				$fileinfo = array (
					'name' => $afile['name'],
					//'path' => $afile['savepath'],
	'src' => str_replace('//', '/', $uppath . $afile['savename']),
					'md5' => $afile['hash'],
					'ext' => strtolower($afile['extension']),
					'size' => $afile['size'],
					//'mime' => $afile['type']
	
				);
				$fileinfo['path'] = str_replace($uppath, '', $fileinfo['src']);
				$filedata[] = $fileinfo;
			}
			$fnum = count($filedata);
			return $filedata;
		}
	}
	public function getSetting($name = ''){
		if(empty($name)) return 0;
		$mset = M('Setting');
		$map['name'] = $name;
		return $mset->where($map)->getField('val');
	}
	
}
?>
	